/**
 * TO BE DETERMINED
 */
package org.eichar.client.question;

import org.eichar.client.I18N;
import org.eichar.client.LanguageConstants;
import org.eichar.client.LanguageMessages;
import org.eichar.client.WidgetFactory;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class TranslationDataEntry extends Composite {

    /**
     * Creates new instance
     */
    public TranslationDataEntry(I18N i18n, WidgetFactory widgetFactory) {
        LanguageConstants constants = i18n.getConstants();
        LanguageMessages messages = i18n.getMessages();

        VerticalPanel panel = widgetFactory.createVerticalPanel();
        panel.setSize("100%", "100%"); //$NON-NLS-1$//$NON-NLS-2$
        panel.setStyleName("white-background"); //$NON-NLS-1$

        Label label = widgetFactory.createLabel(constants.enterTranslation(),
                true);
        panel.add(label);

        // TODO add ListBoxes containing the legal choices of languages
        // TODO make hard coded language not hard coded

        HorizontalPanel entryPanel = widgetFactory.createHorizontalPanel();
        entryPanel.setSize("100%", "100%"); //$NON-NLS-1$//$NON-NLS-2$
        Widget word1 = createTextArea(
                messages.enterPhrase("English"), widgetFactory); //$NON-NLS-1$
        entryPanel.add(word1);

        Widget word2 = createTextArea(
                messages.enterPhrase("Deutsch"), widgetFactory); //$NON-NLS-1$
        entryPanel.add(word2);

        Widget categories = createTextArea(i18n.getConstants().categoryHint(),
                widgetFactory);
        entryPanel.add(categories);

        panel.add(entryPanel);

        Button add = widgetFactory.createButton(constants.add());
        Button clear = widgetFactory.createButton(constants.clear());

        HorizontalPanel buttonPanel = widgetFactory.createHorizontalPanel();
        buttonPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
        buttonPanel.add(add);
        buttonPanel.add(clear);

        panel.add(buttonPanel);
        panel.setCellHorizontalAlignment(buttonPanel, DockPanel.ALIGN_RIGHT);

        initWidget(panel);
    }

    private static Widget createTextArea(String hint,
            WidgetFactory widgetFactory) {
        VerticalPanel panel = widgetFactory.createVerticalPanel();
        panel.setSize("100%", "100%"); //$NON-NLS-1$//$NON-NLS-2$

        TextBox word = widgetFactory.createTextBox();
        word.setSize("100%", "100%"); //$NON-NLS-1$//$NON-NLS-2$
        panel.add(word);

        Label hintWidget = widgetFactory.createLabel(hint);
        hintWidget.setSize("100%", "100%"); //$NON-NLS-1$//$NON-NLS-2$
        hintWidget.setStyleName("hint"); //$NON-NLS-1$

        panel.add(hintWidget);
        panel
                .setCellHorizontalAlignment(hintWidget,
                        VerticalPanel.ALIGN_CENTER);

        return panel;
    }
}